import java.io.File;
import java.util.List;

import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
import org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.apache.mahout.cf.taste.recommender.Recommender;
import org.apache.mahout.cf.taste.similarity.ItemSimilarity;


public class MyItemBasedRecommender {
	public List<RecommendedItem> myItemBasedRecommender(long userId, int size) {
		List<RecommendedItem> recommendations = null;
		try {
			DataModel model = new FileDataModel(new File("data/ratingsForMahout.dat"));
			ItemSimilarity similarity = new PearsonCorrelationSimilarity(model);
			Recommender recommender = new GenericItemBasedRecommender(model, similarity);
			recommendations = recommender.recommend(userId, size);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return recommendations;
	}
	
	public static void main(String args[]) throws Exception {
		MyItemBasedRecommender recommender = null;
		List<RecommendedItem> items = null;
		
		// do the basic item-based recommender
		recommender = new MyItemBasedRecommender();
		items = recommender.myItemBasedRecommender(1, 20);
		
		for (RecommendedItem item : items) {
			System.out.println(item);
		}
	}
}